package com.youhong.teethcare

import android.graphics.Color
import android.os.Bundle
import android.text.Html
import android.text.Spanned
import android.util.Log
import android.view.View
import com.youhong.cuptime.blesdk.Util
import com.youhong.teethcare.javabeans.BrushingRecord
import com.youhong.teethcare.utils.BrushShowUtils
import kotlinx.android.synthetic.main.activity_brush_area_show.*

class BrushAreaShowActivity : BaseActivity() {
    private val TAG = "BrushAreaShowActivity"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_brush_area_show)
        init();
    }

    fun init() {
        iv_back.setOnClickListener { finish() }
        var record = intent.getSerializableExtra("record") as BrushingRecord;
        var dataType=record.type;
        var date = record.startTime;

        when(dataType){
            1 -> showOffLineRecord()
            else -> showOnlineRecord(record)
        }
        tvModeDate.text = Util.FormDateTime2String(date)

    }

    fun showOnlineRecord(record: BrushingRecord){
        var mode=record.brushMode;
        var modeName=resources.getStringArray(R.array.brushModes)[mode];
        var percent = record.percent;
        var brushCount=record.surfaceCount;
        tvBrushCleanCount.text="$brushCount "+getString(R.string.Brush_Clean);
        tv_tips.text = getTipsScore(percent);
        tvReordScore.text = percent.toString();
        tvModeName.text=modeName
        circleView_score.setBackProgressColor(Color.BLACK, 25)
        circleView_score.setProgressColor(Color.WHITE)
        circleView_score.update(percent / 100f)
        getArea(record)
    }
    fun getTipsScore(score: Int): Spanned {
        var tipsString = "";
        if (score == 100) {
            tipsString = String.format(resources.getString(R.string.history_str2), "100%")
        } else if (score < 60) {
            tipsString = resources.getString(R.string.history_str1)
        } else {
            tipsString = resources.getString(R.string.history_str3)
        }
        return Html.fromHtml(tipsString);
    }
    fun showOffLineRecord(){
        iv_record_offline.visibility=View.VISIBLE;
        circleView_score.visibility=View.GONE;
        tvReordScore.visibility=View.GONE;
        tvCoverage.visibility=View.GONE;
        tvRemainingTimeDays.visibility=View.GONE;
        tvModeName.visibility=View.INVISIBLE
        tvBrushCleanCount.text=getString(R.string.not_paired)
        tv_tips.text=resources.getString(R.string.strings32)
    }
    fun getArea(record: BrushingRecord) {

        BrushAreaShowView.updateAreaList(BrushShowUtils.HistoryBrushAreaUtils.getArea(record))
    }

}